
#include "static_table_mgr.h"

#include <nel/misc/file.h>
#include <nel/net/service.h>
#include <game_share/string_spliter.h>
#include <string>

using namespace std;
using namespace NLMISC;

_DBC_BUILDING_LEVEL_DEFINE* CStaticTableMgr::GetBuildingLevel( sint id )
{
	_DBC_BUILDING_LEVEL_DEFINE* pBuildingLevel = NULL;

	TBUILDING_LEVEL::iterator iter = m_BuildLevel.find(id);
	if ( iter != m_BuildLevel.end() )
	{
		pBuildingLevel = &(iter->second);
	}

	return pBuildingLevel;
}




bool CStaticTableMgr::init()
{
	bool res = false;

	string static_table_dir = NLNET::IService::getInstance ()->ConfigFile.getVar("StaticTableDir").asString();
	if ( static_table_dir.size() > 0 )
	{
		NLMISC::CPath::addSearchPath(static_table_dir);
		res = true;
	}
	
	return res;
}

bool CStaticTableMgr::load_building_level()
{
	bool res = false;


	string build_level = NLNET::IService::getInstance ()->ConfigFile.getVar("BuildingLevel").asString();

	//_DBC_BUILDING_LEVEL_DEFINE



	if ( build_level.size() > 0 )
	{
		CIFile inFile;
		if (inFile.open(NLMISC::CPath::lookup(build_level)))
		{
			char pFileBuff[2048] = {0};
			while ( !inFile.eof() )
			{
				inFile.getline(pFileBuff,2048);

				_DBC_BUILDING_LEVEL_DEFINE building_level;
				//sprintf(pFileBuff, "%s%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\n",
				//	pFileBuff, 
				//	itBuild->nSequence,
				//	it->second->m_nWorldID,
				//	itBuild->Building.nResID,
				//	itBuild->Building.nLevel,
				//	(int)itBuild->Building.point.x,
				//	(int)itBuild->Building.point.y,
				//	(int)itBuild->uEndTime,
				//	itBuild->nBuildType,
				//	itBuild->strBuildTime.c_str(),
				//	itBuild->strTotalBuildTime.c_str(),
				//	itBuild->strBuildDesc.c_str());
			}
			
			


			res = true;
			inFile.close();
		}
	}

	return res;
}












